<?php
namespace Modules\Home\Controllers;

class NoticeController extends ControllerBase {
  public function initialize() {
    parent::initialize();

    $this -> _checkLogin();
    $this -> view -> setLayout('index');
  }

  public function indexAction() {
    $this -> tag -> prependTitle('公告');

    $currentPage = abs($this -> request -> getQuery('page', 'int', 1));
    if($currentPage <= 0) {
      $currentPage = 1;
    }

    $pagerXfhNotice = new \Phalcon\Paginator\Pager(new \Phalcon\Paginator\Adapter\QueryBuilder([
      'builder' => $this -> modelsManager -> createBuilder() -> from('Common\\Models\\XfhNoticeModel') -> columns('notice_id,create_time,title') -> orderBy('notice_id DESC'),
      'limit' => 10,
      'page' => $currentPage
    ]), [
      'layoutClass' => 'Modules\\Home\\Libraries\\Paginator\\Pager\\Layout\\Bootstrap',
      'rangeLength' => 5,
      'urlMask' => '?page={%page_number}'
    ]);

    $this -> view -> setVar('pagerXfhNotice', $pagerXfhNotice);
  }

  public function detailAction() {
    $noticeId = abs($this -> request -> getQuery('notice_id', 'int', 0));

    $xfhNotice = \Common\Models\XfhNoticeModel::findFirst('notice_id = ' . $noticeId);
    $this -> view -> setVar('xfhNotice', $xfhNotice);

    $this -> tag -> prependTitle($xfhNotice -> title);
  }
}
?>